home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et-2_2.lha / et2.2 / src / ScrollBar.C < prev    next >
C/C++ Source or Header  |  1990-12-04  |  4KB  |  156 lines

  1. //$ScrollBarButton,ScrollBar$
  2. #include "ScrollBar.h"
  3. #include "Slider.h"
  4. #include "Buttons.h"
  5. #include "ObjectTable.h"
  6.  
  7. const int eScrollBarUpLeft      = cPartLast + 0,
  8.       eScrollBarDownRight   = cPartLast + 1,
  9.       eScrollBarSlider      = cPartLast + 2;
  10.  
  11. static u_short UpArrowBits[]= {
  12. #   include "images/UpArrow.image"
  13. };
  14. static u_short InvUpArrowBits[]= {
  15. #   include "images/UpArrowInv.image"
  16. };
  17. static u_short DownArrowBits[]= {
  18. #   include "images/DownArrow.image"
  19. };
  20. static u_short InvDownArrowBits[]= {
  21. #   include "images/DownArrowInv.image"
  22. };
  23. static u_short LeftArrowBits[]= {
  24. #   include "images/LeftArrow.image"
  25. };
  26. static u_short InvLeftArrowBits[]= {
  27. #   include "images/LeftArrowInv.image"
  28. };
  29. static u_short RightArrowBits[]= {
  30. #   include "images/RightArrow.image"
  31. };
  32. static u_short InvRightArrowBits[]= {
  33. #   include "images/RightArrowInv.image"
  34. };
  35.  
  36. static Bitmap *ArrowUp, *InvArrowUp, *ArrowDown, *InvArrowDown,
  37.           *ArrowLeft, *InvArrowLeft, *ArrowRight, *InvArrowRight;
  38.  
  39. //---- ScrollBarButton ---------------------------------------------------------
  40.  
  41. class ScrollBarButton: public ImageButton {
  42. public:
  43.     ScrollBarButton(int id, Bitmap *b1, Bitmap *b2) : ImageButton(id, b1, b2, TRUE)
  44.     { SetFlag(eVObjHFixed | eVObjVFixed); }
  45.     void DrawInner(Rectangle r, bool highlight);
  46.     Metric GetMinSize()
  47.     { return ImageButton::GetMinSize().extent + gPoint4; }
  48. };
  49.  
  50. void ScrollBarButton::DrawInner(Rectangle r, bool highlight)
  51. {
  52.     contentRect= contentRect.Inset(2);
  53.     ImageButton::DrawInner(r, highlight);
  54.     contentRect= contentRect.Expand(2);
  55.     GrStrokeRect(contentRect);
  56. }
  57.  
  58. //---- ScrollBar ---------------------------------------------------------------
  59.  
  60. MetaImpl(ScrollBar, (TP(slider), 0));
  61.  
  62. ScrollBar::ScrollBar(int id, Direction v) : Expander(id, v)
  63. {
  64.     if (v && ArrowUp == 0)
  65.     ObjectTable::AddRoots(
  66.         ArrowUp= new Bitmap(16, UpArrowBits),
  67.         InvArrowUp= new Bitmap(16, InvUpArrowBits),
  68.         ArrowDown= new Bitmap(16, DownArrowBits),
  69.         InvArrowDown= new Bitmap(16, InvDownArrowBits),
  70.         0
  71.     );
  72.     if (!v && ArrowLeft == 0)
  73.     ObjectTable::AddRoots(
  74.         ArrowLeft= new Bitmap(16, LeftArrowBits),
  75.         InvArrowLeft= new Bitmap(16, InvLeftArrowBits),
  76.         ArrowRight= new Bitmap(16, RightArrowBits),
  77.         InvArrowRight= new Bitmap(16, InvRightArrowBits),
  78.         0
  79.     );
  80.     Add(new ScrollBarButton(eScrollBarUpLeft, v ? ArrowUp : ArrowLeft,
  81.                           v ? InvArrowUp : InvArrowLeft));
  82.     Add(slider= new Slider(eScrollBarSlider, v));
  83.     Add(new ScrollBarButton(eScrollBarDownRight, v ? ArrowDown : ArrowRight,
  84.                          v ? InvArrowDown : InvArrowRight));
  85. }
  86.  
  87. void ScrollBar::Draw(Rectangle r)
  88. {
  89.     // GrSetPenNormal();
  90.     // GrStrokeRect(contentRect);
  91.     Expander::Draw(r);
  92. }
  93.  
  94. void ScrollBar::ViewSizeChanged(Point vsz)
  95. {
  96.     slider->SetMax(vsz, TRUE);
  97. }
  98.  
  99. void ScrollBar::BubbleUpdate(Point relOrig)
  100. {
  101.     slider->SetVal(relOrig, TRUE);
  102. }
  103.  
  104. void ScrollBar::SetThumbRange(Point sz)
  105. {
  106.     slider->SetThumbRange(sz, TRUE);
  107. }
  108.  
  109. void ScrollBar::Init(Point e, Point sz, Point vsz)
  110. {
  111.     SetExtent(e);
  112.     slider->SetThumbRange(sz);
  113.     slider->SetMax(vsz, TRUE);
  114. }
  115.  
  116. void ScrollBar::Control(int id, int part, void *val)
  117. {
  118.     Point scroll;
  119.     
  120.     switch (id) {
  121.     case eScrollBarUpLeft:
  122.     part= cPartScrollStep;
  123.     scroll[dir]= -1;
  124.     break;
  125.     case eScrollBarDownRight:
  126.     part= cPartScrollStep;
  127.     scroll[dir]= 1;
  128.     break;
  129.     case eScrollBarSlider:
  130.     switch (part) {
  131.     case eSliderPageUpLeft:
  132.         part= cPartScrollPage;
  133.         scroll[dir]= -1;
  134.         break;
  135.     case eSliderPageDownRight:
  136.         part= cPartScrollPage;
  137.         scroll[dir]= 1;
  138.         break;
  139.     case eSliderThumb:
  140.         if (dir) {
  141.         part= cPartScrollVAbs;
  142.         scroll.y= ((Point*) val)->y;
  143.         } else {
  144.         part= cPartScrollHAbs;
  145.         scroll.x= ((Point*) val)->x;
  146.         }
  147.         break;
  148.     }
  149.     break;
  150.     default:
  151.     VObject::Control(id, part, val);
  152.     return;
  153.     }
  154.     VObject::Control(GetId(), part, &scroll);
  155. }
  156.